package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.Round;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 千里之外<br/>
 * 让我送你离开！增加己方全体{0=10#0}%速度，持续{1=2#0}回合
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90095 extends CombatSkill {

	public COMBAT_SKILL_90095(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		List<CombatUnit> units = action.unit.getTeam().all();
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied()) {
				// speed
				action.addBuff(new BUFF(skill, unit));
			}
		}
	}
	
	static class BUFF extends CombatBuff {
		int oldAttackSpeed;
		public BUFF(Skill skill, CombatUnit owner) {
			super(skill.getTemplate().getCombatBuff(), owner, (int) skill.getParameter(1));
			active = true;
			int speed = owner.getAttackSpeed();
			oldAttackSpeed = speed;
			speed += speed * skill.getParameter(0) / GameStaticConfig.percentBase;
			owner.setAttributeValue(CombatAttributeType.ATTACK_SPEED, speed);
		}
		@Override
		public void roundEnd(Round round) {
			super.roundEnd(round);
			if (state == STATE_REMOVED) {
				owner.setAttributeValue(CombatAttributeType.ATTACK_SPEED, oldAttackSpeed);
			}
		}
	}

}
